package com.wallet.my.controller;

import com.wallet.my.controller.model.TransContractRequest;
import com.wallet.my.service.ContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Map;

/**
 * 智能合约相关接口
 **/
@RestController
@RequestMapping("/Api")
public class ContractController {
    @Autowired
    private ContractService contractService;

    //    部署智能合约
    @PostMapping("/newContract")
    public Map<String,Object> newContract(@RequestBody TransContractRequest transContractRequest){
        String fromAddr = transContractRequest.getFromAddr();
        String privateKey = transContractRequest.getPrivateKey();
        String data = transContractRequest.getData();
        BigDecimal money = new BigDecimal(transContractRequest.getMoney());
        BigInteger gasLimit = new BigInteger(transContractRequest.getGasLimit());
        contractService.newContract(fromAddr,privateKey,data,money,gasLimit);


        return null;
    }
}
